Example Notebook for Correcting and loading FastCCD Images

This example reads data from the FastCCD and corrects and rotates the images. Included are some example of widgets to interact with the data

Getting Started

Load the databroker moudle, csxtools and various other dependencies

import numpy as np
from databroker import DataBroker, get_table
from csxtools.utils import get_fastccd_images
from csxtools.ipynb import image_stack_to_movie, show_image_stack
%matplotlib inline
from matplotlib import pyplot as plt

Get the data!

Load the headers without the images (using fill=False)

bgnd = DataBroker['ce5042b7-00ae-49ca-9b11-b10c5661aaaa'] #[52440]
print(bgnd)
get_table(bgnd, fill=False)
header
======

  EventDescriptor
  ---------------
  +-----------------------+--------+------------+------------------+--------------------------------------------+
  | data keys             | dtype  |  external  |      shape       |                   source                   |
  +-----------------------+--------+------------+------------------+--------------------------------------------+
  | delta                 | number |            |        []        |     PV:XF:23ID1-ES{Dif-Ax:Del}Mtr.RBV      |
  | epu1_gap              | number |            |        []        |      PV:XF:23ID-ID{EPU:1-Ax:Gap}Pos-I      |
  | epu1_phase            | number |            |        []        |     PV:XF:23ID-ID{EPU:1-Ax:Phase}Pos-I     |
  | epu2_gap              | number |            |        []        |      PV:XF:23ID-ID{EPU:2-Ax:Gap}Pos-I      |
  | epu2_phase            | number |            |        []        |     PV:XF:23ID-ID{EPU:2-Ax:Phase}Pos-I     |
  | eta                   | number |            |        []        |    PV:XF:23ID1-ES{Diag:1-Ax:Eta}Mtr.RBV    |
  | fccd_acquire_period   | number |            |        []        | PV:XF:23ID1-ES{FCCD}cam1:AcquirePeriod_RBV |
  | fccd_acquire_time     | number |            |        []        |  PV:XF:23ID1-ES{FCCD}cam1:AcquireTime_RBV  |
  | fccd_image_lightfield | array  | FILESTORE: | [1200, 960, 960] |            PV:XF:23ID1-ES{FCCD}            |
  | fccd_stats_total1     | number |            |        []        |    PV:XF:23ID1-ES{FCCD}Stats1:Total_RBV    |
  | fccd_stats_total2     | number |            |        []        |    PV:XF:23ID1-ES{FCCD}Stats2:Total_RBV    |
  | fccd_stats_total3     | number |            |        []        |    PV:XF:23ID1-ES{FCCD}Stats3:Total_RBV    |
  | fccd_stats_total4     | number |            |        []        |    PV:XF:23ID1-ES{FCCD}Stats4:Total_RBV    |
  | fccd_stats_total5     | number |            |        []        |    PV:XF:23ID1-ES{FCCD}Stats5:Total_RBV    |
  | gamma                 | number |            |        []        |     PV:XF:23ID1-ES{Dif-Ax:Gam}Mtr.RBV      |
  | npbx                  | number |            |        []        |  PV:XF:23ID1-ES{Dif:Lens-Ax:BtmX}Mtr.RBV   |
  | npby                  | number |            |        []        |  PV:XF:23ID1-ES{Dif:Lens-Ax:BtmY}Mtr.RBV   |
  | npbz                  | number |            |        []        |  PV:XF:23ID1-ES{Dif:Lens-Ax:BtmZ}Mtr.RBV   |
  | nptx                  | number |            |        []        |  PV:XF:23ID1-ES{Dif:Lens-Ax:TopX}Mtr.RBV   |
  | npty                  | number |            |        []        |  PV:XF:23ID1-ES{Dif:Lens-Ax:TopY}Mtr.RBV   |
  | nptz                  | number |            |        []        |  PV:XF:23ID1-ES{Dif:Lens-Ax:TopZ}Mtr.RBV   |
  | pgm_energy            | number |            |        []        |        PV:XF:23ID1-OP{Mono}Enrgy-I         |
  | ring_curr             | number |            |        []        |             PV:XF:23ID-SR{}I-I             |
  | say                   | number |            |        []        |      PV:XF:23ID1-ES{Dif-Ax:Y}Mtr.RBV       |
  | saz                   | number |            |        []        |      PV:XF:23ID1-ES{Dif-Ax:Z}Mtr.RBV       |
  | sclr_chan1            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S1          |
  | sclr_chan2            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S2          |
  | sclr_chan3            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S3          |
  | sclr_chan4            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S4          |
  | sclr_chan5            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S5          |
  | sclr_chan6            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S6          |
  | sclr_chan7            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S7          |
  | sclr_chan8            | number |            |        []        |         PV:XF:23ID1-ES{Sclr:1}.S8          |
  | sclr_time             | number |            |        []        |          PV:XF:23ID1-ES{Sclr:1}.T          |
  | slt1_xc               | number |            |        []        |    PV:XF:23ID1-OP{Slt:1-Ax:XCtr}Mtr.RBV    |
  | slt1_xg               | number |            |        []        |    PV:XF:23ID1-OP{Slt:1-Ax:XGap}Mtr.RBV    |
  | slt1_yc               | number |            |        []        |    PV:XF:23ID1-OP{Slt:1-Ax:YCtr}Mtr.RBV    |
  | slt1_yg               | number |            |        []        |    PV:XF:23ID1-OP{Slt:1-Ax:YGap}Mtr.RBV    |
  | slt2_xc               | number |            |        []        |    PV:XF:23ID1-OP{Slt:2-Ax:XCtr}Mtr.RBV    |
  | slt2_xg               | number |            |        []        |    PV:XF:23ID1-OP{Slt:2-Ax:XGap}Mtr.RBV    |
  | slt2_yc               | number |            |        []        |    PV:XF:23ID1-OP{Slt:2-Ax:YCtr}Mtr.RBV    |
  | slt2_yg               | number |            |        []        |    PV:XF:23ID1-OP{Slt:2-Ax:YGap}Mtr.RBV    |
  | slt3_x                | number |            |        []        |     PV:XF:23ID1-OP{Slt:3-Ax:X}Mtr.RBV      |
  | slt3_y                | number |            |        []        |     PV:XF:23ID1-OP{Slt:3-Ax:Y}Mtr.RBV      |
  | sx                    | number |            |        []        |      PV:XF:23ID1-ES{Dif-Ax:X}Mtr.RBV       |
  | sy                    | number |            |        []        |      PV:XF:23ID1-ES{Dif-Ax:SY}Pos-RB       |
  | sz                    | number |            |        []        |      PV:XF:23ID1-ES{Dif-Ax:SZ}Pos-RB       |
  | temp_a                | number |            |        []        |     PV:XF:23ID1-ES{TCtrl:1-Chan:A}T-I      |
  | temp_b                | number |            |        []        |     PV:XF:23ID1-ES{TCtrl:1-Chan:B}T-I      |
  | theta                 | number |            |        []        |      PV:XF:23ID1-ES{Dif-Ax:Th}Mtr.RBV      |
  +-----------------------+--------+------------+------------------+--------------------------------------------+
  run_start       : ce5042b7-00ae-49ca-9b11-b10c5661aaaa
  time            : 1445472638.1676164
  uid             : 29645582-4748-41e5-bd9b-95c22c122446

  RunStart
  --------
  beamline_id     : CSX
  config          :
  group           :
  owner           : xf23id1
  project         :
  sample          :
  scan_args       :
    delay           : 0
    detectors       : [EpicsMotor(name='theta', record='XF:23ID1-ES{Dif-Ax:Th}Mtr'), EpicsMotor(name='delta', record='XF:23ID1-ES{Dif-Ax:Del}Mtr'), EpicsMotor(name='gamma', record='XF:23ID1-ES{Dif-Ax:Gam}Mtr'), EpicsMotor(name='sx', record='XF:23ID1-ES{Dif-Ax:X}Mtr'), PVPositioner(name='sy', setpoint='XF:23ID1-ES{Dif-Ax:SY}Pos-SP', readback='XF:23ID1-ES{Dif-Ax:SY}Pos-RB', stop='XF:23ID1-ES{Dif-Cryo}Cmd:Stop-Cmd', stop_val=1, put_complete=True, settle_time=0.05, limits=(0, 0)), PVPositioner(name='sz', setpoint='XF:23ID1-ES{Dif-Ax:SZ}Pos-SP', readback='XF:23ID1-ES{Dif-Ax:SZ}Pos-RB', stop='XF:23ID1-ES{Dif-Cryo}Cmd:Stop-Cmd', stop_val=1, put_complete=True, settle_time=0.05, limits=(0, 0)), EpicsMotor(name='say', record='XF:23ID1-ES{Dif-Ax:Y}Mtr'), EpicsMotor(name='saz', record='XF:23ID1-ES{Dif-Ax:Z}Mtr'), EpicsSignal(name='temp_a', read_pv='XF:23ID1-ES{TCtrl:1-Chan:A}T-I', rw=False, string=False, limits=False, put_complete=False, pv_kw={}, auto_monitor=None), EpicsSignal(name='temp_b', read_pv='XF:23ID1-ES{TCtrl:1-Chan:B}T-I', rw=False, string=False, limits=False, put_complete=False, pv_kw={}, auto_monitor=None), PVPositioner(name='pgm_energy', setpoint='XF:23ID1-OP{Mono}Enrgy-SP', readback='XF:23ID1-OP{Mono}Enrgy-I', stop='XF:23ID1-OP{Mono}Cmd:Stop-Cmd', stop_val=1, put_complete=True, settle_time=0.05, limits=(200, 2200)), PVPositioner(name='epu1_gap', setpoint='XF:23ID-ID{EPU:1-Ax:Gap}Pos-SP', readback='XF:23ID-ID{EPU:1-Ax:Gap}Pos-I', stop='SR:C23-ID:G1A{EPU:1-Ax:Gap}-Mtr.STOP', stop_val=1, put_complete=True, settle_time=0.05, limits=(0, 0)), PVPositioner(name='epu1_phase', setpoint='XF:23ID-ID{EPU:1-Ax:Phase}Pos-SP', readback='XF:23ID-ID{EPU:1-Ax:Phase}Pos-I', stop='SR:C23-ID:G1A{EPU:1-Ax:Phase}-Mtr.STOP', stop_val=1, put_complete=True, settle_time=0.05, limits=(0, 0)), PVPositioner(name='epu2_gap', setpoint='XF:23ID-ID{EPU:2-Ax:Gap}Pos-SP', readback='XF:23ID-ID{EPU:2-Ax:Gap}Pos-I', stop='SR:C23-ID:G1A{EPU:2-Ax:Gap}-Mtr.STOP', stop_val=1, put_complete=True, settle_time=0.05, limits=(0, 0)), PVPositioner(name='epu2_phase', setpoint='XF:23ID-ID{EPU:2-Ax:Phase}Pos-SP', readback='XF:23ID-ID{EPU:2-Ax:Phase}Pos-I', stop='SR:C23-ID:G1A{EPU:2-Ax:Phase}-Mtr.STOP', stop_val=1, put_complete=True, settle_time=0.05, limits=(0, 0)), EpicsMotor(name='eta', record='XF:23ID1-ES{Diag:1-Ax:Eta}Mtr'), EpicsMotor(name='slt1_xc', record='XF:23ID1-OP{Slt:1-Ax:XCtr}Mtr'), EpicsMotor(name='slt1_xg', record='XF:23ID1-OP{Slt:1-Ax:XGap}Mtr'), EpicsMotor(name='slt1_yc', record='XF:23ID1-OP{Slt:1-Ax:YCtr}Mtr'), EpicsMotor(name='slt1_yg', record='XF:23ID1-OP{Slt:1-Ax:YGap}Mtr'), EpicsMotor(name='slt2_xc', record='XF:23ID1-OP{Slt:2-Ax:XCtr}Mtr'), EpicsMotor(name='slt2_xg', record='XF:23ID1-OP{Slt:2-Ax:XGap}Mtr'), EpicsMotor(name='slt2_yc', record='XF:23ID1-OP{Slt:2-Ax:YCtr}Mtr'), EpicsMotor(name='slt2_yg', record='XF:23ID1-OP{Slt:2-Ax:YGap}Mtr'), EpicsMotor(name='slt3_x', record='XF:23ID1-OP{Slt:3-Ax:X}Mtr'), EpicsMotor(name='slt3_y', record='XF:23ID1-OP{Slt:3-Ax:Y}Mtr'), EpicsSignal(name='ring_curr', read_pv='XF:23ID-SR{}I-I', rw=False, string=False, limits=False, put_complete=False, pv_kw={}, auto_monitor=None), EpicsMotor(name='npbx', record='XF:23ID1-ES{Dif:Lens-Ax:BtmX}Mtr'), EpicsMotor(name='npby', record='XF:23ID1-ES{Dif:Lens-Ax:BtmY}Mtr'), EpicsMotor(name='npbz', record='XF:23ID1-ES{Dif:Lens-Ax:BtmZ}Mtr'), EpicsMotor(name='nptx', record='XF:23ID1-ES{Dif:Lens-Ax:TopX}Mtr'), EpicsMotor(name='npty', record='XF:23ID1-ES{Dif:Lens-Ax:TopY}Mtr'), EpicsMotor(name='nptz', record='XF:23ID1-ES{Dif:Lens-Ax:TopZ}Mtr'), EpicsScaler(name='sclr', record='XF:23ID1-ES{Sclr:1}', numchan=8), AreaDetectorFileStoreHDF5(name='fccd', basename='XF:23ID1-ES{FCCD}', stats=[1, 2, 3, 4, 5], shutter=None, shutter_rb=None, shutter_val=None, file_path='/GPFS/xf23id/xf23id1/fccd_data/', ioc_file_path=None)]
    num             : 1
  scan_id         : 52440
  scan_type       : Count
  time            : 1445472516.9860468
  uid             : ce5042b7-00ae-49ca-9b11-b10c5661aaaa

  RunStop
  -------
  exit_status     : success
  reason          :
  run_start       : ce5042b7-00ae-49ca-9b11-b10c5661aaaa
  time            : 1445472638.2573586
  uid             : 2bf2d671-d8a5-4fb9-b592-798db66b98a0
time sclr_chan5 slt2_yc fccd_stats_total1 epu2_gap delta theta slt1_xg npby npty ... fccd_acquire_period sclr_chan8 slt3_x epu1_phase slt3_y fccd_stats_total3 saz sclr_time nptz fccd_image_lightfield
1 2015-10-22 00:10:38.185091-04:00 423651 -5.0001 137150246 31.020917 38.999985 19.499985 6.9994 -12.47033 -26.662465 ... 1 0 11.26975 -0.000045 -0.09925 86706314 4.175332 8.000000e-08 6.21667 7180b59d-5112-428e-b6a4-9bc8893220b0

1 rows × 51 columns

data = DataBroker['b2596f8e-d220-4aea-8a55-8ccb17cbdacc'] #[52436]
get_table(data, fill=False)
time sclr_chan5 slt2_yc fccd_stats_total1 epu2_gap delta theta slt1_xg npby npty ... fccd_acquire_period sclr_chan8 slt3_x epu1_phase slt3_y fccd_stats_total3 saz sclr_time nptz fccd_image_lightfield
1 2015-10-21 23:59:54.531477-04:00 423638 -5.0001 137233260 31.020912 38.999985 19.499985 6.9994 -12.470325 -26.66246 ... 1 0 11.26979 -0.000045 -0.09926 86779381 4.175332 8.000000e-08 6.216685 20eed5d8-05e2-4b0e-bd3c-5edae7b15878

1 rows × 51 columns

Correct the FastCCD Images

Now correct the CCD images, using only a single background image.

In the future this should be taken from the metadata associated with the data, or from the darkfield entry

images = get_fastccd_images(data, (bgnd, None, None))

Now lets do an interactive plotting widget!

Thanks ipywidgets!

show_image_stack(images, (-100, 100))
../_images/Correct_FastCCD_Images_9_0.png

And lets do a movie of the stack of images

This produces an HTML5 movie which can be viewed in most browsers

image_stack_to_movie(images, frames=100, figsize=(12, 10), vmin=-20, vmax=20)

What version are we running?

import csxtools
csxtools.__version__
'0+untagged.192.gc8f9f5f.dirty'